package com.campus.activity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.campus.activity.entity.Registration;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 报名信息Mapper接口
 * 
 * @author System
 * @since 2024
 */
@Mapper
public interface RegistrationMapper extends BaseMapper<Registration> {

    /**
     * 根据学生ID查询报名记录
     * 
     * @param studentId 学生ID
     * @return 报名记录列表
     */
    @Select("SELECT * FROM registration WHERE student_id = #{studentId} AND deleted = 0")
    List<Registration> selectByStudentId(@Param("studentId") Integer studentId);

    /**
     * 根据活动ID查询报名记录
     * 
     * @param activityId 活动ID
     * @return 报名记录列表
     */
    @Select("SELECT * FROM registration WHERE activity_id = #{activityId} AND deleted = 0")
    List<Registration> selectByActivityId(@Param("activityId") Integer activityId);

    /**
     * 根据活动ID和学生ID查询报名记录
     * 
     * @param activityId 活动ID
     * @param studentId 学生ID
     * @return 报名记录
     */
    @Select("SELECT * FROM registration WHERE activity_id = #{activityId} AND student_id = #{studentId} AND deleted = 0")
    Registration selectByActivityIdAndStudentId(@Param("activityId") Integer activityId, 
                                             @Param("studentId") Integer studentId);

    /**
     * 根据报名状态查询报名记录
     * 
     * @param registrationStatus 报名状态
     * @return 报名记录列表
     */
    @Select("SELECT * FROM registration WHERE registration_status = #{registrationStatus} AND deleted = 0")
    List<Registration> selectByStatus(@Param("registrationStatus") String registrationStatus);

    /**
     * 统计活动报名情况
     * 
     * @param activityId 活动ID
     * @return 统计结果
     */
    @Select("SELECT registration_status, COUNT(*) as count FROM registration WHERE activity_id = #{activityId} AND deleted = 0 GROUP BY registration_status")
    List<Map<String, Object>> countByActivityId(@Param("activityId") Integer activityId);

    /**
     * 统计活动总报名人数
     * 
     * @param activityId 活动ID
     * @return 总报名人数
     */
    @Select("SELECT COUNT(*) FROM registration WHERE activity_id = #{activityId} AND deleted = 0")
    Integer countTotalByActivityId(@Param("activityId") Integer activityId);

    /**
     * 统计活动已通过报名人数
     * 
     * @param activityId 活动ID
     * @return 已通过报名人数
     */
    @Select("SELECT COUNT(*) FROM registration WHERE activity_id = #{activityId} AND registration_status = '审核通过' AND deleted = 0")
    Integer countApprovedByActivityId(@Param("activityId") Integer activityId);
}